Ensure we can load images via resource:// uris from CSS
authorAlexander Larsson <alexl@redhat.com>
Mon, 16 Jan 2012 10:18:42 +0000 (11:18 +0100)
committerAlexander Larsson <alexl@redhat.com>
Mon, 16 Jan 2012 13:19:19 +0000 (14:19 +0100)
gtk/gtkcssimageurl.c
gtk/gtkcssparser.c

index 2f1cca9a4743170c8b09136d56ce55e2ce2bc263..a548d93125a65693118f41836a164025aceb396d 100644 (file)
@@ -67,19 +67,25 @@ gtk_css_image_url_parse (GtkCssImage  *image,
   GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
   GdkPixbuf *pixbuf;
   GFile *file;
-  char *path;
   cairo_t *cr;
   GError *error = NULL;
+  GFileInputStream *input;
 
   file = _gtk_css_parser_read_url (parser, base);
   if (file == NULL)
     return FALSE;
 
-  path = g_file_get_path (file);
+  input = g_file_read (file, NULL, &error);
+  if (input == NULL)
+    {
+      _gtk_css_parser_take_error (parser, error);
+      return FALSE;
+    }
   g_object_unref (file);
 
-  pixbuf = gdk_pixbuf_new_from_file (path, &error);
-  g_free (path);
+  pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
+  g_object_unref (input);
+
   if (pixbuf == NULL)
     {
       _gtk_css_parser_take_error (parser, error);
index cf87ef929a744830b4578b5c4396ac66e32e134d..44b00c305cc9a7d62af08350b95e7bc1b0dd244c 100644 (file)
@@ -873,6 +873,7 @@ _gtk_css_parser_read_url (GtkCssParser *parser,
                           GFile        *base)
 {
   gchar *path;
+  char *scheme;
   GFile *file;
 
   if (_gtk_css_parser_try (parser, "url", FALSE))
@@ -907,6 +908,15 @@ _gtk_css_parser_read_url (GtkCssParser *parser,
           g_free (path);
           return NULL;
         }
+
+      scheme = g_uri_parse_scheme (path);
+      if (scheme != NULL)
+       {
+         file = g_file_new_for_uri (path);
+         g_free (path);
+         g_free (scheme);
+         return file;
+       }
     }
   else
     {